package com.lonewalker.completablefuturedemo;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * @author LoneWalker
 * @date 2023/2/12
 * @description
 */
public class demo4 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        CompletableFuture<Integer> completableFuture1 = CompletableFuture.supplyAsync(() -> {
//            System.out.println(Thread.currentThread().getName());
//            return 5;
//        }).thenApply(result ->{
//            System.out.println(Thread.currentThread().getName());
//            return result+5;
//        });
//
//        System.out.println(completableFuture1.get());


        CompletableFuture<Integer> completableFuture2 = CompletableFuture.supplyAsync(() -> {
            System.out.println(Thread.currentThread().getName());
            int a = 1/0;
            return 5;
        }).thenApplyAsync(result ->{
            System.out.println(Thread.currentThread().getName());
            return result+5;
        });

        System.out.println(completableFuture2.get());
    }
}
